//
//  StockRankView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/6.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "StockRankView.h"
#import "StockBrankTableViewCell.h"

static NSString *rankCellID = @"rankCellID";

@interface StockRankView ()<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) UIView *topView;
@property (strong, nonatomic) UIImageView *bgIV;
@property (strong, nonatomic) UIImageView *smallIV;
//@property (strong, nonatomic) UILabel *stockL;
@property (strong, nonatomic) UILabel *integralL;

@property (strong, nonatomic) UIView *sliderView;

@property (strong, nonatomic) UIView *rankTbg;
@property (strong, nonatomic) UITableView *rankTableView;

@end

@implementation StockRankView

- (instancetype)init {
    
    if (self == [super init]) {
        
        [self addSubview:self.bgIV];
        [self addSubview:self.topView];
        [self.topView addSubview:self.smallIV];
//        [self.topView addSubview:self.stockL];
        [self.topView addSubview:self.integralL];
        [self.topView addSubview:self.sliderView];
        
        [self addSubview:self.rankTbg];
        [self.rankTbg addSubview:self.rankTableView];
        
    }
    
    return self;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return jisuan(60);
}

#pragma mark -delegate\ datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 5;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    StockBrankTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:rankCellID];
    
    if (!cell) {
        
        cell = [[StockBrankTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:rankCellID];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;

}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.mas_equalTo(weakSelf.mas_centerX);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.width.mas_equalTo(jisuan(750));
        make.height.mas_equalTo(jisuan(250));

    }];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.mas_left);
        make.right.mas_equalTo(weakSelf.mas_right);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.height.mas_equalTo(jisuan(80));

    }];
    [self.smallIV mas_makeConstraints:^(MASConstraintMaker *make) {

//        make.centerX.mas_equalTo(weakSelf.topView.mas_centerX);
        
        make.left.mas_equalTo(weakSelf.topView.mas_left).with.offset(jisuan(256));
        make.centerY.mas_equalTo(weakSelf.topView.mas_centerY);
        make.width.mas_equalTo(jisuan(41));
        make.height.mas_equalTo(jisuan(27));
    }];

//    [self.stockL sizeToFit];

//    [self.stockL mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.centerY.mas_equalTo(weakSelf.topView.mas_centerY);
//        make.right.mas_equalTo(weakSelf.smallIV.mas_left).with.offset(-jisuan(80));
//
//    }];

    [self.integralL sizeToFit];
    [self.integralL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(weakSelf.topView.mas_centerY);
        make.left.mas_equalTo(weakSelf.smallIV.mas_right).with.offset(jisuan(40));

    }];
    
    [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.integralL.mas_left);
        make.right.mas_equalTo(weakSelf.integralL.mas_right);
        make.bottom.mas_equalTo(weakSelf.topView.mas_bottom).with.offset(-jisuan(10));
        make.height.mas_equalTo(jisuan(4));
    }];

//    [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.left.mas_equalTo(weakSelf.stockL.mas_left);
//        make.right.mas_equalTo(weakSelf.stockL.mas_right);
//        make.bottom.mas_equalTo(weakSelf.topView.mas_bottom).with.offset(-jisuan(10));
//        make.height.mas_equalTo(jisuan(4));
//    }];
    
    [self.rankTbg mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left).with.offset(Margin);
        make.right.mas_equalTo(weakSelf.mas_right).with.offset(-Margin);
        make.top.mas_equalTo(weakSelf.topView.mas_bottom);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
        
    }];

    [self.rankTableView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.rankTbg.mas_left);
        make.right.mas_equalTo(weakSelf.rankTbg.mas_right);
        make.top.mas_equalTo(weakSelf.rankTbg.mas_top).with.offset(jisuan(30));
        make.bottom.mas_equalTo(weakSelf.rankTbg.mas_bottom).with.offset(-jisuan(30));
        
    }];

}



#pragma mark -lazy
- (UIView *)topView {
    
    if (!_topView) {
        
        _topView = [[UIView alloc] init];
        
    }
    
    return _topView;
}

- (UIImageView *)bgIV {
    
    if (!_bgIV) {
        
        _bgIV = [[UIImageView alloc] init];
        _bgIV.image = [UIImage imageNamed:@"rankView"];
        _bgIV.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    
    return _bgIV;
}
- (UIImageView *)smallIV {
  
    if (!_smallIV) {
        
        _smallIV = [[UIImageView alloc] init];
        _smallIV.image = [UIImage imageNamed:@"rankViewSmallBG"];
        _smallIV.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    
    return _smallIV;
    
}

//- (UILabel *)stockL {
//
//    if (!_stockL) {
//
//        _stockL = [[UILabel alloc] init];
//        _stockL.textAlignment = NSTextAlignmentCenter;
//        _stockL.textColor = WhiteColor;
//        _stockL.font = [UIFont fontWithName:@"Helvetica-Bold" size:jisuan(30)];
//        _stockL.text = @"进货排行榜";
//
//    }
//
//    return _stockL;
//
//}

- (UILabel *)integralL {
    
    if (!_integralL) {
        
        _integralL = [[UILabel alloc] init];
        _integralL.font = [UIFont fontWithName:@"Helvetica-Bold" size:jisuan(30)];
        _integralL.textColor = WhiteColor;
        _integralL.textAlignment = NSTextAlignmentCenter;
        _integralL.text = @"积分排行榜";
        
    }
    
    return _integralL;
    
}

- (UIView *)sliderView {
    
    if (!_sliderView) {
        
        _sliderView = [[UIView alloc] init];
        _sliderView.backgroundColor = Colorfff000;
    }
    
    return _sliderView;
}

- (UIView *)rankTbg {
    
    if (!_rankTbg) {
        
        _rankTbg = [[UIView alloc] init];
        _rankTbg.backgroundColor = WhiteColor;

    }

    return _rankTbg;
}

- (UITableView *)rankTableView {
    
    if (!_rankTableView) {
    
        _rankTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        
        _rankTableView.backgroundColor = WhiteColor;
        
        _rankTableView.delegate = self;
        _rankTableView.dataSource = self;
        
        _rankTableView.scrollEnabled = NO;
        
        _rankTableView.showsVerticalScrollIndicator = NO;
        _rankTableView.showsHorizontalScrollIndicator = NO;
        
        _rankTableView.estimatedRowHeight = 0;
        _rankTableView.estimatedSectionFooterHeight = 0;
        _rankTableView.estimatedSectionHeaderHeight = 0;
        
        _rankTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        if (@available(iOS 11.0, *)) {
            
            _rankTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }

    }

    return _rankTableView;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
